package com.yycwxt.modules.admin.xstj;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.yycwxt.common.BaseService;
import com.yycwxt.domain.Xstj;
import com.yycwxt.modules.admin.data_import.AccountData;
import com.yycwxt.modules.admin.data_import.ImpFile;
import com.yycwxt.modules.admin.data_import.ImpFileMapper;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
public class XstjService extends BaseService<ImpFileMapper, ImpFile> {

    private final XstjMapper xstjMapper;

    public XstjService(@Autowired XstjMapper xstjMapper){
        this.xstjMapper = xstjMapper;
    }

    @SneakyThrows
    @Transactional
    public void importXstj(MultipartFile file) {
        EasyExcel.read(file.getInputStream(), Xstj.class, new ReadListener<Xstj>() {

            private static final int BATCH_SIZE = 1000;


            @Override
            public void invoke(Xstj data, AnalysisContext context) {

                System.out.println(data);

                // 执行存储过程
                xstjMapper.importKdfdzd(AccountData.getAccountDate(), data.getDp(), data.getXse(),
                        data.getTke(), data.getSdje(), data.getSc(),
                        data.getSjxsje(), data.getXsdd(), data.getSddd(),
                        data.getDds(),data.getSdyj(),data.getZtc(),data.getCjtj()
                        ,data.getZszw(),data.getTbk(),data.getJd(),data.getPdd());
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }
        }).sheet().doRead();
    }

}
